package jdbc10_18;

import java.sql.*;

public class DBUtil {
    private DBUtil(){

    }
    public static final String DRIVER ="com.mysql.cj.jdbc.Driver";
    public static final String URl="jdbc:mysql://localhost:3306/jv75";
    public static final String USER="root";
    public static final String PASS="123456";
    static {
        try {
            Class<?> aClass = Class.forName(DRIVER);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    public static Connection getConnection(){
        try {
            return DriverManager.getConnection(URl,USER,PASS);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
    public static void close(Connection con,PreparedStatement ps,ResultSet rs){
       close(con);
       close(ps);
       close(rs);
    }
    public static void close(Connection con){
      if (con!=null) {
          try {
              con.close();
          } catch (SQLException e) {
              e.printStackTrace();
          }
      }
    }
    public static void close(PreparedStatement ps){
        if (ps!=null) {
            try {
                ps.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    public static void close(ResultSet rs){
        if (rs!=null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
